package com.example.freshmenapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class StandardWeightActivity extends AppCompatActivity implements View.OnClickListener {
    EditText etHeight;
    private RadioGroup rgGender;
    private RadioButton rbMale;
    private RadioButton rbFemale;
    private Button btnCompute;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_standard_weight);

        etHeight = findViewById(R.id.et_height);
        rgGender = findViewById(R.id.rg_gender);
        rbMale = findViewById(R.id.rb_male);
        rbFemale = findViewById(R.id.rb_female);
        btnCompute = findViewById(R.id.btn_compute);

        btnCompute.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        int height;
        String gender;
        double standardWeight;
        height = Integer.parseInt(etHeight.getText().toString());
        int checkedRadioButtonId = rgGender.getCheckedRadioButtonId();
        if(checkedRadioButtonId == R.id.rb_male){
            gender ="男";
        }else {
            gender = "女";
        }
        if(gender.equals("男")){
            standardWeight= (height -100)*0.9;
        }else{
            standardWeight= (height -100)*0.9 -2.5;
        }
        Toast.makeText(this, "标准体重为"+standardWeight, Toast.LENGTH_SHORT).show();

    }
}